package controller;

import annotation.Controller;
import annotation.DependencyInjection;
import annotation.RequestMapping;
import annotation.Singleton;
import enums.RequestType;
import request.relation.*;
import response.relation.*;
import service.RelationService;

@Singleton
@Controller
public class RelationController {
    private RelationService relationService;

    @DependencyInjection
    public RelationController(RelationService relationService) {
        this.relationService = relationService;
    }

    @RequestMapping(RequestType.FriendList)
    public FriendListResponse getAllFriendUsernames(FriendListRequest request) {
        return relationService.getAllFriendUsernames(request.getUsername());
    }

    @RequestMapping(RequestType.RelationState)
    public RelationStateResponse getRelationState(RelationStateRequest request) {
        return relationService.getRelationState(request.getHostUsername(), request.getGuestUsername());
    }

    @RequestMapping(RequestType.FriendAdd)
    public FriendAddResponse addFriendRequest(FriendAddRequest request) {
        return relationService.addFriendRequest(request.getHostUsername(), request.getGuestUsername());
    }

    @RequestMapping(RequestType.FriendPullApplication)
    public FriendPullApplicationResponse pullFriendRequests(FriendPullApplicationRequest request) {
        return relationService.getFriendRequests(request.getUsername());
    }

    @RequestMapping(RequestType.FriendAddDecision)
    public FriendAddDecisionResponse makeAddDecision(FriendAddDecisionRequest request) {
        return relationService.dealAddRequest(request.getHostUsername(), request.getGuestUsername(), request.isAccept());
    }
}
